package com.gemfire.onlineretailer.domain;

/**
 * Unlike Misc. Parties, the Vendors have a regular business relation with the Organization. They are registered and receive and fulfill purchase order at regular intervals.  
 * @author Binit Datta
 */

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;

public class Vendor implements DataSerializable {
	  private static final long serialVersionUID = 1L;
	  
	  public static final long VENDOR_1 = 10000001;
	  public static final long VENDOR_2 = 10000002;

	  public static final long VENDOR_3 = 10000003;
	  public static final long VENDOR_4 = 10000004;
	  public static final long VENDOR_5 = 10000005;
	  
	  public static final String VENDOR_1_CODE = "10000001";
	  public static final String VENDOR_2_CODE = "10000002";

	  public static final String VENDOR_3_CODE = "10000003";
	  public static final String VENDOR_4_CODE = "10000004";
	  public static final String VENDOR_5_CODE = "10000005";
	  
	  
	  private long vendorId;
	  private String vendorCode;
	  private String vendorName;
	  private String emailpyeeEmailAddress;
	  private Address vendorMailingAddress;
	  private String vendorContactPhone;
	  private String vendorContactCellPhone;
	  private int TIN;
	  
	public long getVendorId() {
		return vendorId;
	}
	public void setVendorId(long vendorId) {
		this.vendorId = vendorId;
	}
	public String getVendorCode() {
		return vendorCode;
	}
	public void setVendorCode(String vendorCode) {
		this.vendorCode = vendorCode;
	}
	public String getVendorName() {
		return vendorName;
	}
	public void setVendorName(String vendorName) {
		this.vendorName = vendorName;
	}
	public String getEmailpyeeEmailAddress() {
		return emailpyeeEmailAddress;
	}
	public void setEmailpyeeEmailAddress(String emailpyeeEmailAddress) {
		this.emailpyeeEmailAddress = emailpyeeEmailAddress;
	}
	public Address getVendorMailingAddress() {
		return vendorMailingAddress;
	}
	public void setVendorMailingAddress(Address vendorMailingAddress) {
		this.vendorMailingAddress = vendorMailingAddress;
	}
	public String getVendorContactPhone() {
		return vendorContactPhone;
	}
	public void setVendorContactPhone(String vendorContactPhone) {
		this.vendorContactPhone = vendorContactPhone;
	}
	public String getVendorContactCellPhone() {
		return vendorContactCellPhone;
	}
	public void setVendorContactCellPhone(String vendorContactCellPhone) {
		this.vendorContactCellPhone = vendorContactCellPhone;
	}
	public int getTIN() {
		return TIN;
	}
	public void setTIN(int tIN) {
		TIN = tIN;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	  
	
public static Vendor createInstance(long vendorId){
		
		/*
		 * Use accountHeadId to read from DB or from other source, Hardcode for now
		 */
		
		Vendor vendor = new Vendor();
		
		if (vendorId == VENDOR_1){
			vendor.setVendorId(vendorId);
			vendor.setVendorCode(VENDOR_1_CODE);
			vendor.setVendorName("United Electronics");
		} 
		else if (vendorId == VENDOR_2){
			vendor.setVendorId(vendorId);
			vendor.setVendorCode(VENDOR_2_CODE);
			vendor.setVendorName("United Building Materials");

		} 
		else if (vendorId == VENDOR_3){
			vendor.setVendorId(vendorId);
			vendor.setVendorCode(VENDOR_3_CODE);
			vendor.setVendorName("United Packaging Materials");
		} 
		else if (vendorId == VENDOR_4){
			vendor.setVendorId(vendorId);
			vendor.setVendorCode(VENDOR_4_CODE);
			vendor.setVendorName("United Chemicals");
		}
		
		
		return vendor;
		
	}
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
	this.vendorId = in.readLong();
	this.vendorCode = in.readUTF();
	this.vendorName = in.readUTF();
	this.vendorMailingAddress = (Address) DataSerializer.readObject(in);
	this.vendorContactPhone = in.readUTF();
	this.vendorContactCellPhone = in.readUTF();
	this.TIN = in.readInt();
}
@Override
public void toData(DataOutput out) throws IOException {
	
	out.writeLong(this.vendorId);
	out.writeUTF(this.vendorCode);
	out.writeUTF(this.vendorName);
	out.writeUTF(this.emailpyeeEmailAddress);
	DataSerializer.writeObject(this.vendorMailingAddress, out);
	out.writeUTF(this.vendorContactPhone);
	out.writeUTF(this.vendorContactCellPhone);
	out.writeInt(this.TIN);
}
	  
	  

}
